package com.vgtech.vantop;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import net.glxn.qrgen.QRCode;
import net.glxn.qrgen.image.ImageType;

public class QRCodeUtil {
	
	
	public static void createQRCode(String localURL, String imgName, String text){
		QRCode qrcode = QRCode.from(text);
		ByteArrayOutputStream out = qrcode.to(ImageType.PNG).stream();
		try {
			FileOutputStream fout = new FileOutputStream(new File(localURL+"\\"+imgName	));//"E:\\logs\\QR_Code.JPG"

			fout.write(out.toByteArray());

			fout.flush();
			fout.close();

		} catch (FileNotFoundException e) {
			// Do Logging
		} catch (IOException e) {
			// Do Logging
		}
		
		// get QR file from text using defaults
		File file = qrcode.file();
		// get QR stream from text using defaults
		ByteArrayOutputStream stream = qrcode.stream();

		// override the image type to be JPG
		qrcode.to(ImageType.JPG).file();
		qrcode.to(ImageType.JPG).stream();

		// override image size to be 250x250
		qrcode.withSize(250, 250).file();
		qrcode.withSize(250, 250).stream();

		// override size and image type
		qrcode.to(ImageType.GIF).withSize(250, 250).file();
		qrcode.to(ImageType.GIF).withSize(250, 250)
				.stream();

		// Website Link (URLs) QR Code in Java
		ByteArrayOutputStream out1 = QRCode.from("http://viralpatel.net")
				.to(ImageType.PNG).stream();
	
		
		
	}
	

	public static void main(String[] args) {
		ByteArrayOutputStream out = QRCode.from("Hello World")
				.to(ImageType.PNG).stream();

		try {
			FileOutputStream fout = new FileOutputStream(new File(
					"E:\\logs\\QR_Code.JPG"));

			fout.write(out.toByteArray());

			fout.flush();
			fout.close();

		} catch (FileNotFoundException e) {
			// Do Logging
		} catch (IOException e) {
			// Do Logging
		}

		// get QR file from text using defaults
		File file = QRCode.from("Hello World").file();
		// get QR stream from text using defaults
		ByteArrayOutputStream stream = QRCode.from("Hello World").stream();

		// override the image type to be JPG
		QRCode.from("Hello World").to(ImageType.JPG).file();
		QRCode.from("Hello World").to(ImageType.JPG).stream();

		// override image size to be 250x250
		QRCode.from("Hello World").withSize(250, 250).file();
		QRCode.from("Hello World").withSize(250, 250).stream();

		// override size and image type
		QRCode.from("Hello World").to(ImageType.GIF).withSize(250, 250).file();
		QRCode.from("Hello World").to(ImageType.GIF).withSize(250, 250)
				.stream();

		// Website Link (URLs) QR Code in Java
		ByteArrayOutputStream out1 = QRCode.from("http://viralpatel.net")
				.to(ImageType.PNG).stream();
	}

}
